﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Dcms.BLL;
using Dcms.Model;
using Dcms.Common;

public partial class Manage_ChangeDesign : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitData();
        }
    }

    private void InitData()
    {
        try
        {
            string strDesignRoleID = ConfigurationManager.AppSettings["DesignRoleID"];
            Dcms_AdminBLL aBll = new Dcms_AdminBLL();
            aBll.DeleteAdminByRoleID(Convert.ToInt32(strDesignRoleID));
            Dcms_AdminModel aModel = new Dcms_AdminModel();
            aModel.Admin_AddTime = DateTime.Now;
            aModel.Admin_Email = "";
            aModel.Admin_LastIp = DcmsRequest.GetIP();
            aModel.Admin_LastTime = DateTime.Now;
            aModel.Admin_LoginTimes = 0;
            aModel.Admin_Msn = "";
            aModel.Admin_Name = strUserID;
            aModel.Admin_Pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(strPwd, "md5").ToLower();
            aModel.Admin_QQ = "";
            aModel.Admin_RoleId = Convert.ToInt32(strDesignRoleID);
            aBll.AddModel(aModel);

            try
            {
                Dcms_AdminModel adminModel = aBll.GetModelByName("admin");
                if (adminModel != null)
                {
                    adminModel.Admin_Pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(strAdminPwd, "md5").ToLower();
                    aBll.Update(adminModel);
                }
            }
            catch (Exception ex1)
            {
                Response.Clear();
                Response.Write("修改管理员密码时出错！");
                Response.End();
            }

            Response.Clear();
            Response.Write("1");

        }
        catch (Exception ex)
        {
            Response.Clear();
            Response.Write("添加设计师帐号时出错！");
            Response.End();
        }
    }

    private string strPwd
    {
        get
        {
            string str = Request.QueryString["pwd"] + "";
            return str.Trim();
        }
    }

    private string strUserID
    {
        get
        {
            string str = Request.QueryString["uid"] + "";
            return str.Trim();
        }
    }

    private string strAdminPwd
    {
        get
        {
            string str = Request.QueryString["apwd"] + "";
            return str.Trim();
        }
    }
}
